package cn.hackcloud.designpattern.observer;

import java.util.ArrayList;
import java.util.List;

public class WeatherData implements Subject {

	private float temperature;
	private float pressure;
	private float humidity;

	List<Observer> observers;

	public WeatherData() {
		this.observers = new ArrayList<Observer>();
	}

	private void dataChange() {
		notifyObserver();
	}

	public void setDate(float temperature, float pressure, float humidity) {
		this.temperature = temperature;
		this.pressure = pressure;
		this.humidity = humidity;
		dataChange();
	}

	@Override
	public void registerObserver(Observer o) {
		observers.add(o);
	}

	@Override
	public void rermoveObserver(Observer o) {
		observers.remove(o);
	}

	@Override
	public void notifyObserver() {
		for (Observer observer : observers) {
			observer.update(temperature, pressure, humidity);
		}
	}

}
